﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FazaDemo.BL.Domain;
using FazaDemoSolution.BL.Domain.AbstractCore;
using FazaDemo.BL.Factories;
using FazaDemo.BL.DataAccess;
using FazaDemo.Data;
using FazaDemo.PL.Mapping;

namespace FazaDemo.BL.Services
{
    public class DataServicePoint<T> : IDataServicePoint<T> where T : class
    {

        private readonly IRepository<TS_STREET, int> repository;

        private readonly ILowToTopMapper<TS_STREET, Street> _mapper;

        public DataServicePoint()
        {
            repository = new EntityRepository<TS_STREET, int>();
            _mapper = new LowToTopMapper<TS_STREET, Street>();
        }

        public IEnumerable<T> Get()
        {
            var loadResult = repository.GetAll() as List<TS_STREET>;
            var result = new List<Street>(); 
            foreach (var res in loadResult)
            {
                result.Add(_mapper.MapFrom(res));
            }
            return result as IEnumerable<T>;
        }
    }
}
